//package cn.rui.config;
//
//import org.springframework.boot.SpringApplication;
//import org.springframework.boot.env.EnvironmentPostProcessor;
//import org.springframework.core.env.ConfigurableEnvironment;
//import org.springframework.core.env.MapPropertySource;
//import org.springframework.core.env.PropertiesPropertySource;
//import org.springframework.core.env.PropertySource;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.core.io.Resource;
//
//import java.io.IOException;
//import java.net.Inet4Address;
//import java.net.InetAddress;
//import java.net.UnknownHostException;
//import java.util.HashMap;
//import java.util.Properties;
//
/////**
//// * @author 徽州大都督
//// * @date 2021/7/8
//// */
////
//public class EnviromentConfig implements EnvironmentPostProcessor {
//
//    private final Properties properties = new Properties();
//    private static final String SERVER_ADDRESS = "server.address";
//    private String[] profiles = {
//            "application.properties",
//    };
//
//    @Override
//    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
//
//        // 获取当前应用中的配置信息
//        //String property = environment.getProperty(SERVER_ADDRESS);
//
//        // 自定义修改后添加进去覆盖
//        HashMap<String, Object> map = new HashMap<>(1);
//
//
//        //获取本机IP
//        InetAddress localHost = null;
//        try {
//            localHost = Inet4Address.getLocalHost ();
//        } catch (UnknownHostException e) {
//            e.printStackTrace ();
//        }
//        map.put (SERVER_ADDRESS, localHost.getHostAddress ());
//
//        PropertySource source = new MapPropertySource ("xixi", map);
//        environment.getPropertySources().addFirst(source);
//
//        //添加自定义环境信息
//        for (String profile : profiles) {
//            Resource resource = new ClassPathResource (profile);
//            try {
//                properties.load(resource.getInputStream());
//                environment.getPropertySources().addLast(new PropertiesPropertySource (resource.getFilename(), properties));
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//
//    }
//}
